package com.xul.crowd.controller;

import com.xul.crowd.api.MysqlRemoteService;
import com.xul.crowd.constant.CrowdConstant;
import com.xul.crowd.util.ResultEntity;
import com.xul.entity.vo.PortalTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author xul
 * @create 2021-07-28 23:50
 */
@Controller
public class PortalController {

    @Autowired
    private MysqlRemoteService mysqlRemoteService;

    /**
     * 跳转开始页面
     *
     * @param model
     * @return
     */
    @RequestMapping("/")
    public String showPortalPage(Model model) {
        // 1.调用MySQLRemoteService提供方法查询首页要显示的数据
        ResultEntity<List<PortalTypeVO>> resultPortalTypeVO = mysqlRemoteService.getPortalTypeProjectDataRemote();
        // 2.检查查询结果
        String result = resultPortalTypeVO.getResult();
        if (ResultEntity.SUCCESS.equals(result)) {
            // 3.获取查询结果数据
            List<PortalTypeVO> portalTypeVOList = resultPortalTypeVO.getData();
            // 4.存入数据模型
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, portalTypeVOList);
        }
        return "portal";
    }
}
